package com.vtest.quartz.service.impl.vtest.report;

import com.vtest.quartz.domain.vtest.report.MCMWeekHoldEntity;
import com.vtest.quartz.mapper.vtest.report.MCMMapper;
import com.vtest.quartz.service.vtest.report.MCMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: Quartz
 * @author: tiger
 * @create: 2025-02-06 08:51
 * @Description : MCM service 层
 */

@Service
public class MCMServiceImpl implements MCMService {

    @Autowired
    private MCMMapper mcmMapper;

    @Override
    public List<MCMWeekHoldEntity> getHoldInfo() {
        List<MCMWeekHoldEntity> holdInfoList = mcmMapper.findHoldInfoList();
        for (MCMWeekHoldEntity mcmWeekHoldEntity : holdInfoList) {

            mcmWeekHoldEntity.setReMark("低良待放行");

            if (mcmWeekHoldEntity.getStage().equals("ENG") || mcmWeekHoldEntity.getStage().equals("SRP")) {
                mcmWeekHoldEntity.setReMark("低良待通知后处理");
            }

            String waferNo = mcmWeekHoldEntity.getWaferNo();
            waferNo = waferNo.replace(",", "、");
            waferNo = waferNo.replace("#", "");
            String[] swids = waferNo.split("、");
            for (int j = 0; j < swids.length; j++) {
                String swid = swids[j];
                if (swid.contains("-")) {
                    String[] split = swid.split("-");
                    int begin = Integer.parseInt(split[0]);
                    int end = Integer.parseInt(split[1]);
                    String newS = "";
                    for (int i = begin; i <= end; i++) {
                        newS += i;
                        if (i != end) newS += "、";
                    }
                    swids[j] = newS;
                }
            }
            String newWafer = String.join("、", swids);

            mcmWeekHoldEntity.setWaferNo(newWafer);

        }

        return holdInfoList;
    }
}
